\name{doEM}
\alias{doEM}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{
Fitting Nested Mixture Models
}
\description{
'doEM' is used to fit nested mixture models using EM algorithm.
}
\usage{
doEM(d, z, w, k, l, mu, var, C_limit = 50, V = FALSE, label = NULL,
    THRESH = 1e-10, THEORET = FALSE, FV = FALSE, shu_cnt_thresh = 10)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
  \item{d}{
Matrix of Data (row:gene, column: sample).
}
  \item{z}{
Initial gene class indication matrix.
}
  \item{w}{
Initial sample class indication matrix.
}
  \item{k}{
Initial gene class probabilities matrix.
}
  \item{l}{
Initial sample class probabilities matrix.
}
  \item{mu}{
Initial mean parameters.
}
  \item{var}{
Initial variance parameters.
}
  \item{C_limit}{
Limit of the number of iteration of EM algorithm.
}
  \item{V}{
Verbose mode.
}
  \item{label}{
Label text for generated graphs.
}
  \item{THRESH}{
Threshold for convergence judgement
}
  \item{THEORET}{
True if theoretical null for nomal samples is used.
}
  \item{FV}{
True if fixed variances are used.
}
  \item{shu_cnt_thresh}{
Threshold for the number gene/sample identification shuffling 
}
}
\details{
%%  ~~ If necessary, more details than the description above ~~
}
\value{
%%  ~Describe the value returned
%%  If it is a LIST, use
%%  \item{comp1 }{Description of 'comp1'}
%%  \item{comp2 }{Description of 'comp2'}
%% ...
'doEM' returns a list containing follwoing components:

    \item{z}{gene class indicator.}
    \item{w}{sample class indicator.}
    \item{k}{gene class probability.}
    \item{l}{sample class probability.}
    \item{mu}{mean parameters.}
    \item{var}{variance parameters.}
    \item{AIC}{Akaike Information Criterion.}
    \item{BIC}{Bayesian Information Criteria.}
    \item{ICL}{Integrated Classification Likelihood.}
    \item{EN}{Entropy.}
    \item{c_it}{Count of iterations.}
    \item{shu_it}{Shuffling indicator for each iteration.}
    \item{LL}{likelihood.}
    \item{res}{Residual.}
    \item{LL}{Log likelihood versus iteration.}
}
\references{
%% ~put references to the literature/web site here ~
}
\author{
Tomonori Oura
}
\note{
%%  ~~further notes~~
}

%% ~Make other sections like Warning with \section{Warning }{....} ~

\seealso{
%% ~~objects to See Also as \code{\link{help}}, ~~~
}
\examples{
library(nmixclust)

#Generate simulated data
set.seed(123)
simData <- makeSimulationData(
	m=2000
	,n=200
	,prop.DE=0.5
	,effect.size=2
	,ngc=4
	,dist="norm"
	,model_type=1
)

#Data generated
str(simData)

#Normalization by median and mad of normal samples
non.cancer <- simData$class==1
d.med <- apply(simData$data[, non.cancer],1,median)
d.mad <- apply(simData$data[, non.cancer],1,mad)
d <- (simData$data - d.med) / d.mad

#Execute initialization
initClassList <- doInitClass(
	d=d
	,class=simData$class
	,n.class=c(2:6)
)

#Initialized gene/sample classes
str(initClassList)

initClass <- initClassList[[3]]

z_ini <- initClass$z
w_ini <- initClass$w
k_ini <- initClass$k
l_ini <- initClass$l
mu_ini <- initClass$mu
var_ini <- initClass$var
nc <- initClass$nc


d.c <- d[, simData$class==2]#Restrict cancer samples
w_ini <- w_ini[simData$class==2,,]
l_ini <- l_ini[simData$class==2,,]

#Execute EM algorithm
r.em <- doEM(
	d=d.c
	,z=z_ini
	,w=w_ini
	,k=k_ini
	,l=l_ini
	,mu=mu_ini
	,var=var_ini
	,V=FALSE
	,FV=TRUE
	,C_limit=100
	,label="test"
	,THEORET=TRUE
	,shu_cnt_thresh=20
)

str(r.em)


}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
\keyword{ ~kwd1 }
\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line
